added player_collides_with_entity event

This commit is contained in:
gnembon committed 2020-09-17 21:29:35 -03:00
1 parent 755f3a7840
commit c0707fe544
6 files changed
+38 -6

No files matched your search

@@ -2,6 +2,7 @@ package carpet.mixins;
import carpet.fakes.EntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
@@ -16,6 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import static carpet.script.CarpetEventServer.Event.PLAYER_DEALS_DAMAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_TAKES_DAMAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_COLLIDES_WITH_ENTITY;
@Mixin(PlayerEntity.class)
public abstract class PlayerEntity_scarpetEventsMixin extends LivingEntity
@@ -42,4 +44,13 @@ public abstract class PlayerEntity_scarpetEventsMixin extends LivingEntity
PLAYER_DEALS_DAMAGE.onDamage(this, amount, source);
}
}
@Inject(method = "collideWithEntity", at = @At("HEAD"))
private void onEntityCollision(Entity entity, CallbackInfo ci)
{
if (PLAYER_COLLIDES_WITH_ENTITY.isNeeded() && !world.isClient)
{
PLAYER_COLLIDES_WITH_ENTITY.onEntityAction((ServerPlayerEntity)(Object)this, entity, null);
}
}
}
@@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(WorldChunk.class)
public class WorldChunk_fillUpdatesMixin
{
// todo onStateReplaced needs a bit more love since it removes be which is needed
@Redirect(method = "setBlockState", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;onBlockAdded(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V"
@@ -416,6 +416,7 @@ public class CarpetEventServer
), player::getCommandSource);
}
};
// todo PlayerInventory.insertStack... for definite item inventory pickup, when result protocol has be set
public static final Event PLAYER_ATTACKS_ENTITY = new Event("player_attacks_entity", 2, false)
{
@Override
@@ -578,6 +579,17 @@ public class CarpetEventServer
}, () -> source.getAttacker().getCommandSource());
}
};
public static final Event PLAYER_COLLIDES_WITH_ENTITY = new Event("player_collides_with_entity", 2, false)
{
@Override
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand) {
handler.call( () -> Arrays.asList(
((c, t) -> new EntityValue(player)),
((c, t) -> new EntityValue(entity))
), player::getCommandSource);
}
};
public static final Event PLAYER_DIES = new Event("player_dies", 1, false)
{
@Override
@@ -270,3 +270,10 @@ __on_player_swaps_hands(player) -> (
print('__on_player_swaps_hands(player)');
print(' Player '+player+' swaps hands.')
);
__on_player_collides_with_entity(player, entity) ->
(
print('');
print('__on_player_collides_with_entity(player, entity)');
print(' Player '+player+' collides with '+entity);
)