added handler for on_lightning

This commit is contained in:
gnembon committed 2020-03-26 03:18:49 -03:00
1 parent 73e6c2ce5e
commit c66ed96a98
5 files changed
+50 -1

No files matched your search

@@ -0,0 +1,29 @@
package carpet.mixins;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import static carpet.script.CarpetEventServer.Event.LIGHTNING;
@Mixin(ServerWorld.class)
public class ServerWorld_scarpetEventMixin
{
@Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;addLightning(Lnet/minecraft/entity/LightningEntity;)V"
))
private void onNaturalLightinig(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci,
ChunkPos chunkPos, boolean bl, int i, int j, Profiler profiler, BlockPos blockPos, boolean bl2)
{
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerWorld) (Object)this, blockPos, bl2?1:0);
}
}
@@ -502,7 +502,20 @@ public class CarpetEventServer
((c, t) -> new NumericValue(amount))
), player::getCommandSource);
}
}
},
LIGHTNING("lightning", 2, true)
{
@Override
public void onWorldEventFlag(ServerWorld world, BlockPos pos, int flag)
{
handler.call(
() -> Arrays.asList(
((c, t) -> new BlockValue(null, world, pos)),
((c, t) -> flag>0?Value.TRUE:Value.FALSE)
), () -> CarpetServer.minecraft_server.getCommandSource().withWorld(world)
);
}
},
;
// on projectile thrown (arrow from bows, crossbows, tridents, snoballs, e-pearls
@@ -538,6 +551,8 @@ public class CarpetEventServer
public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS) { }
public void onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack) { }
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand) { }
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
public void onWorldEventFlag(ServerWorld world, BlockPos pos, int flag) { }
}