package com.forgeessentials.core.preloader.mixin.tileentity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.tileentity.MobSpawnerBaseLogic;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(MobSpawnerBaseLogic.class)
public class MixinMobSpawnerBaseLogic
{
    @Inject(method = "Lnet/minecraft/tileentity/MobSpawnerBaseLogic;updateSpawner()V",
            at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setLocationAndAngles(DDDFF)V", shift = Shift.AFTER),
            cancellable = true, locals = LocalCapture.PRINT)
    public void handleUpdateSpawner(CallbackInfo ci)
    {
        System.out.println("Mixin : Spawned entity from mob spawner block");
        /*if (MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn()))
        {
            ci.cancel();
        }*/
    }
}

@@ -282,63 +282,8 @@
 At;%0A
-import org.spongepowered.asm.mixin.injection.At.Shift;%0A
 impo
@@ -554,16 +554,25 @@
 @Inject(
+%0A        
 method =
@@ -577,54 +577,8 @@
  = %22
-Lnet/minecraft/tileentity/MobSpawnerBaseLogic;
 upda
@@ -590,18 +590,11 @@
 wner
-()V%22,%0A    
+%22,%0A
     
@@ -606,16 +606,29 @@
 t = @At(
+%0A            
 value = 
@@ -636,16 +636,28 @@
 INVOKE%22,
+%0A           
  target 
@@ -721,36 +721,20 @@
 F)V%22
-, shift = Shift.AFTER),%0A
+%0A    
     
+),%0A
     
@@ -760,89 +760,236 @@
 rue,
- locals = LocalCapture.PRINT)%0A    public void handleUpdateSpawner(CallbackInfo ci
+%0A        require = 1,%0A        locals = LocalCapture.CAPTURE_FAILEXCEPTION%0A    )%0A    public void handleUpdateSpawner(CallbackInfo ci, double d2, boolean flag, int i, Entity entity, int j, double d3, double d4, EntityLiving living
 )%0A  
@@ -1019,16 +1019,30 @@
 println(
+String.format(
 %22Mixin :
@@ -1056,16 +1056,21 @@
 d entity
+ %5B%25s%5D
  from mo
@@ -1085,16 +1085,36 @@
 r block%22
+, entity.toString())
 );%0A     

Fix MobSpawner injection