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"